Ext.define('NIM.view.AssetDataMaster.site_list', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.site_list',
    id: 'site_list',
    border: false,
    title : 'Site List',
    layout : 'fit',
    closable: true,
    width: 1 * screen.width,
    height: 590,
    items: 
    [ 
	    {
            xtype: 'gridpanel',
            region: 'center',
            titleAlign: 'center',
            title   : 'Site List',
	        margin: '5 5 5 5',
		    height: 0.67*screen.height,
	        selType: 'checkboxmodel',
            columnLines: true,
            forceFit: true,
            store: 'AssetDataMaster.SiteList',
            columns: [
	            { dataIndex: 'site_id', text: 'Site ID', align: 'left'},
	            { dataIndex: 'site_name', text: 'Site Name', align: 'left' },
	            { dataIndex: 'address', text: 'Address', align: 'left' },
	            { dataIndex: 'area_description', text: 'Area', align: 'left' },
	            { dataIndex: 'region_description', text: 'Region', align: 'left' },
	            { dataIndex: 'nama_prov', text: 'Provinsi', align: 'left' },
	            { dataIndex: 'nama_kabkot', text: 'Kabupaten', align: 'left' },
	            { dataIndex: 'nama_kec', text: 'Kecamatan', align: 'left' },
	            { dataIndex: 'on_air_date', text: 'On Air Date', align: 'left' },
	            { dataIndex: 'asset_status', text: 'Status', align: 'center' },
	        ],
		    listeners: {
		    	afterrender: function() {
                    Ext.getStore('AssetDataMaster.SiteList').load();    
//                    console.log('zzzzzzzzzzzzzzzzzzzzzz ' + hasPrivilege('NIM.SITE.VIEW'));
                },
			    itemdblclick: function(grid, record) {
			    	    site_id = record.raw.site_id;
		    	 		OpenTab('widget.addnewsitemaster','addnewsitemaster');
                       
			    	 }
	        	},
            dockedItems: 
            [
             	{
	                xtype: 'pagingtoolbar',
	                dock: 'bottom',
	                store: 'AssetDataMaster.SiteList',
	                displayInfo: true
	            }, 
	            {
	                xtype: 'toolbar',
	                dock: 'top',
	                items: 
                	[
	                	
	                    
		                {
		                	xtype: 'combobox',
		                	id: 'AssetDataArea',
		                	displayField: 'area_description',
		                	valueField: 'area_code',
		                	emptyText       : 'Area',
		                	allowBlank : true,
		                	margin: '0 5 0 5',
		                	width: 125,
		                	store: 'AssetDataMaster.Area',
		                    listeners: {
		                    	select: function(obj, newValue, oldValue, eOpts) {
		                			Ext.getCmp('AssetDataRegional').setValue('');
		                        	Ext.getStore('AssetDataMaster.Regional').removeAll();
		                            Ext.getStore('AssetDataMaster.Regional').getProxy().url = './Services/DataMaster/Region/List?area=' + newValue;
		                            Ext.getStore('AssetDataMaster.Regional').load();
									Ext.getCmp('AssetDataRegional').setValue('');
		                        }
		                    }
		                },
		                {	xtype: 'tbseparator' },
		                {
		                	xtype: 'combobox',
		                	id: 'AssetDataRegional',
		                	displayField: 'region_description',
		                	emptyText       : 'Region',
		                	margin: '0 5 0 5',
		                	width: 160,
		                	valueField: 'region_code',
		                	store: 'AssetDataMaster.Regional',
		                    listeners: {
		                    	select: function(obj, newValue, oldValue, eOpts) {
		                            Ext.getStore('AssetDataMaster.Provinsi').load();
		                        }
		                    }
		                },
		                {	xtype: 'tbseparator' },
		                {
		                	xtype: 'combobox',
		                	id: 'AssetDataProvinsi',
		                	displayField: 'nama_prov',
		                	emptyText       : 'Propinsi',
						 	margin: '0 5 0 5',
						 	width: 155,
						 	store: 'AssetDataMaster.Provinsi',
		                	valueField: 'id_prov',
		                    listeners: {
		                    	select: function(obj, newValue, oldValue, eOpts) {
		                    	    var id_prof = Ext.getCmp("AssetDataProvinsi").getValue();
			                    	Ext.getStore('AssetDataMaster.Kabupaten').removeAll();
		                            Ext.getStore('AssetDataMaster.Kabupaten').getProxy().url = './Services/DataMaster/Kabupaten/List?propinsi=' + id_prof;
		                            Ext.getStore('AssetDataMaster.Kabupaten').load();

		                    	}
		                    }
		                },
		                { xtype: 'tbseparator' },
		                {
		                	xtype: 'combobox',
		                	id: 'AssetDataKabupaten',
		                	displayField: 'nama_kabkot',
		                	emptyText       : 'Kabupaten',
		                	margin: '0 5 0 5',
		                	width: 165,
		                	store: 'AssetDataMaster.Kabupaten',
		                	valueField: 'id_kabkot'
		                },
		                {	xtype: 'tbseparator' },
		                {
		                    xtype: 'textfield',
		                    id: 'AssetDataKeyword',
		                    margin: '0 5 0 5',
		                    labelWidth: 50,
		                    fieldLabel: 'Keyword'
		                },
		                
		                {	xtype: 'tbseparator' },
		                {
		                    xtype: 'button',
		                    id: 'AssetDataMasterSearch',
		                    text: 'Search',
				    		handler: function() {
		                	   //OpenTab('widget.addnewsitemaster','addnewsitemaster');
		                		var keyword = Ext.getCmp('AssetDataKeyword').getValue();
		                		var area = Ext.getCmp('AssetDataArea').getValue();
		                		var region = Ext.getCmp('AssetDataRegional').getValue();
		                		var provinsi = Ext.getCmp('AssetDataProvinsi').getValue();
		                		var kabupaten = Ext.getCmp('AssetDataKabupaten').getValue();	
			            		Ext.getStore('AssetDataMaster.SiteList').removeAll();
			            		Ext.getStore('AssetDataMaster.SiteList').getProxy().url = "./Services/Asset/Site/List?keyword=" + keyword + '&area=' + area + 
			            				"&region=" + region + "&prop=" + provinsi + "&kabkot=" + kabupaten; 
			            		Ext.getStore('AssetDataMaster.SiteList').load();
				    		}
		                },
		                {
		                    xtype: 'button',
		                    id: 'AssetDataMasterAdd',
		                    text: 'Add New',
				    		handler: function() {
	                			site_id = "";	
		                	   	OpenTab('widget.addnewsitemaster','addnewsitemaster');
				    		}
		                }
	                ]
	            }
            ]
        }
    ]
});